<?php
/**
 * Форма авторизації
 *
 */
class Auth_Form extends Zend_Form
{
    /**
     * Ініціалізація елементів форми
     * @return void
     * @see Zend_Form::init()
     */
    public function init()
    {
        $this->setMethod ( 'post' );
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $action = '/' . $request->getControllerName()
                . '/' . $request->getActionName();
        $this->setAction($action);
        $this->setDecorators(array('formElements', 'form'));

        $login = $this->createElement ( 'text', 'login' );
        $login->setLabel ( '[LOGIN]' );
        $login->setRequired ( true );
        $login->setDecorators(array('viewHelper'));
        $login->setAttrib('placeholder', 'Login');
        $this->addElement ( $login );

        $password = $this->createElement ( 'password', 'password' );
        $password->setLabel ( '[PASSWORD]' );
        $password->setRequired ( true );
        $password->setRenderPassword(true);
        $password->setDecorators(array('viewHelper'));
        $password->setAttrib('placeholder', 'Password');
        $this->addElement ( $password );

        $csrf = $this->createElement ( 'hash', 'csrf', array (
                'salt' => 'unique', 'decorators' => array('viewHelper') ) );
        $csrf->setErrorMessages ( array (
                '[ERROR_VALIDATION_FAILED]' ) );
        $this->addElement ( $csrf );

        $submit = $this->createElement('submit', 'signin', 
                                       array (
                                            'label' => '[SIGNIN]', 
                                            'decorators' => array('viewHelper'),
                                            'onclick' => '$("#authForm").submit()'));
        $this->addElement ( $submit );
    }
}
